package com.source.lightfowl.barcodeMachineRepair.controller;


import com.source.lightfowl.barcodeMachineRepair.pojo.MachineScrap;
import com.source.lightfowl.barcodeMachineRepair.service.MachineScrapService;
import com.source.lightfowl.syslog.annotation.LogAnnotation;
import com.source.lightfowl.utils.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;

/**
 * 控制器层
 * @author Administrator
 *
 */
@Api(tags = "脚标机报废管理")
@RestController
@CrossOrigin
@RequestMapping("/machineScrap")
public class MachineScrapController {

	@Autowired
	private MachineScrapService machineScrapService;


	/**
	 * 查询全部数据
	 * @return
	 */
	@ApiOperation(value = "查询全部数据")
	@RequestMapping(method= RequestMethod.GET)
	public MyResult findAll(){
		return MyResult.ok(machineScrapService.findAll());
	}

	/**
	 * 分页查询全部数据
	 * @return
	 */
	@ApiOperation(value = "查询全部数据")
	@GetMapping("/findAllPage")
	public MyResult findAllPage(int page,int pageNum){
		return MyResult.ok(machineScrapService.findAllPage(page,pageNum));
	}

	/**
	 * 根据ID查询
	 * @param id ID
	 * @return
	 */
	@ApiOperation(value = "根据ID查询")
	@RequestMapping(value="/{id}",method= RequestMethod.GET)
	public MyResult findById(@PathVariable BigInteger id){
		return MyResult.ok(machineScrapService.findById(id));
	}


	/**
	 * 增加
	 * @param machineScrap
	 */
	@ApiOperation(value = "增加")
	@PostMapping
	@LogAnnotation(operEvent = "操作类型：添加",operType = 1)
	public MyResult add(MachineScrap machineScrap  ){
		machineScrapService.add(machineScrap);
		return MyResult.ok();
	}

	/**
	 * 修改
	 * @param machineScrap
	 */
	@ApiOperation("修改")
	@PutMapping(value="/{id}")
	@LogAnnotation(operEvent = "操作类型：修改",operType = 2)
	public MyResult update(MachineScrap machineScrap, @PathVariable BigInteger id ){
		machineScrap.setId(id);
		machineScrapService.update(machineScrap);
		return MyResult.ok();
	}

	/**
	 * 删除
	 * @param id
	 */
	@ApiOperation("删除")
	@DeleteMapping(value="/{id}")
	@LogAnnotation(operEvent = "操作类型：删除记录",operType = 3)
	public MyResult delete(@PathVariable BigInteger id ){
		machineScrapService.deleteById(id);
		return MyResult.ok();
	}

}
